import { injectable, injectModel } from "../../../../app-core/inject";
import { BasePresenter } from "../../../../app-core/mvp/base/BasePresenter";
import { ILoginPresenter, ILoginView } from "../contract/LoginContract";
import { LoginModel } from "../model/LoginModel";
import { User } from "../vo/User";

@injectable('LoginPresenter')
export default class LoginPresenter extends BasePresenter<ILoginView> implements ILoginPresenter {

    @injectModel(LoginModel) loginModel: LoginModel;

    onAttach(): void {

    }

    onDetach(): void {
    }

    toLogin() {
        this.loginModel.toLogin(new User()).then((val: true) => {
            if (val) {
                this.getView().loginSuccess();
            } else {
                this.getView().loginFail('fail');
            }

        })
    }

}